package com.woniuxy.controller;

import com.woniuxy.entity.Relationship;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RelationshipService;
import com.woniuxy.utils.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/relationship")
public class RelationshipController {

    @Autowired
    private RelationshipService relationshipService;


    /**
     * 根据场馆ID 查询有哪些关注者
     * @param venueId
     * @return
     */
    @GetMapping("/fans/{venueId}")
    public ResponseEntity<List<Relationship>> findFansByVenueId(@PathVariable("venueId") int venueId) {
        ResponseEntity<List<Relationship>> fansResponseEntity = new ResponseEntity<>();
        List<Relationship> fansByVenueId = relationshipService.findFansByVenueId(venueId);
        if (fansByVenueId.size()<1){
            return fansResponseEntity.setCode(CodeUtils.ERROR_CODE).setMsg("还没有关注你的人哟");
        }
        return fansResponseEntity.setCode(CodeUtils.SUCCESS_CODE)
                .setData(fansByVenueId).setMsg("你的粉丝们都在这了");
    }

    /** 根据场馆ID 查询他关注了谁
     * @param venueId
     * @return
     */
    @GetMapping("/followed/{venueId}")
    public ResponseEntity<List<Relationship>> findFollowedByVenueId(@PathVariable("venueId") int venueId) {
        ResponseEntity<List<Relationship>> followedResponseEntity = new ResponseEntity<>();
        List<Relationship> followedByVenueId = relationshipService.findFollowedByVenueId(venueId);
        if (followedByVenueId.size()<1){
            return followedResponseEntity.setCode(CodeUtils.ERROR_CODE).setMsg("你还没有关注任何人哟");
        }
        return followedResponseEntity.setCode(CodeUtils.SUCCESS_CODE)
                .setData(followedByVenueId).setMsg("你关注的都在这了");
    }
}
